package com.hzp.lolnews.activity.view;

import android.content.Intent;
import android.database.Cursor;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleCursorAdapter;

import com.hzp.lolnews.R;
import com.hzp.lolnews.base.BaseActivity;
import com.hzp.lolnews.db.ShopDao;
import com.hzp.lolnews.ui.novel.view.DetailWenActivity;

public class CollectionActivity extends BaseActivity {


    @Override
    protected void initView() {
        GridView mGv = (GridView) findViewById(R.id.collect_gv);
        ShopDao shopDao = new ShopDao(this);
        final String sql = "select * from history ";
        Cursor cursor = shopDao.select(sql, null);
        final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_item_collect,
                cursor, new String[]{"name", "title"},
                new int[]{R.id.collect_simpleDraweeView, R.id.collect_tv}, SimpleCursorAdapter.FLAG_AUTO_REQUERY);
        mGv.setAdapter(adapter);
        mGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(CollectionActivity.this, DetailWenActivity.class);
                Cursor cursor = (Cursor) adapterView.getItemAtPosition(i);
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String name = cursor.getString(cursor.getColumnIndex("name"));
                intent.putExtra(title,"getArticle_title");
                intent.putExtra(name,"getArticle_pic");
                startActivity(intent);
            }
        });
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_collection;
    }
}
